package edu.byu.intex2.data.bo;

import edu.byu.intex2.data.DataException;
import edu.byu.intex2.data.dao.ConceptualCarDAO;
import edu.byu.intex2.data.dao.TaskDAO;
import edu.byu.intex2.data.dao.TaskCCDAO;

/**
 * Tracks the time it takes to complete each task on a conceptual car
 * @author Brady White
 * @see ConceptualCar, Task
 */
public class TaskCC extends BusinessObject {
    // Labor Time
    private int laborTime;

    // Task
    private String taskId;
    private Task task;

    // ConceptualCar
    private String conceptualCarId;
    private ConceptualCar conceptualCar;

    /** Creates a new instance of BusinessObject */
    public TaskCC(String id) {
        super(id);
    }//constructor

    /** Convenience method to call the correct DAO to save this business object */
    public void save() throws DataException {
        try {
            TaskCCDAO.getInstance().save(this);
        } catch (DataException e) {
            e.printStackTrace();
        }
    }

    /** @return the quantity     */
    public double getLaborTime() {
        return laborTime;
    }

    /** @param actualPrice the actualPrice to set     */
    public void setLaborTime(int laborTime) {
        this.laborTime = laborTime;
        setDirty();
    }

    /** @return the taskId     */
    public String getTaskId() {
        return taskId;
    }

    /** @param taskId the taskId to set     */
    public void setTaskId(String taskId) {
        this.taskId = taskId;
        setDirty();
    }

    /** @return the task     */
    public Task getTask() throws Exception {
        if (task == null) {
            task = TaskDAO.getInstance().read(taskId);
        }
        return task;
    }

    /** @param task the task to set     */
    public void setTask(Task task) {
        this.task = task;
        setDirty();
    }

    /** @return the conceptualCarId     */
    public String getConceptualCarId() {
        if (conceptualCarId == null){
            conceptualCarId = conceptualCar.getId();
        }
        return conceptualCarId;
    }

    /** @param conceptualCarId the conceptualCarId to set     */
    public void setConceptualCarId(String conceptualCarId) {
        this.conceptualCarId = conceptualCarId;
        setDirty();
    }

    /** @return the conceptualCar     */
    public ConceptualCar getConceptualCar() throws Exception {
        if (conceptualCar == null) {
            conceptualCar = ConceptualCarDAO.getInstance().read(conceptualCarId);
        }
        return conceptualCar;
    }

    /** @param conceptualCar the conceptualCar to set     */
    public void setConceptualCar(ConceptualCar conceptualCar) {
        this.conceptualCar = conceptualCar;
        setDirty();
    }
}
